class Queue {
    constructor() {
        this.count = 0;
        this.lowestCount = 0;
        this.items = {};
    }
    isEmpty() {
        return this.count === this.lowestCount;
    }
    enqueue(element) {
        this.items[this.count] = element;
        this.count++;
    }
    dequeue() {
        if (this.isEmpty()) {
            return undefined;
        }
        const result = this.items[this.lowestCount];
        delete this.items[this.lowestCount];
        this.lowestCount++;
        return result;
    }
    peek() {
        if (this.isEmpty()) {
            return undefined;
        }
        return this.items[this.lowestCount];
    }
    size() {
        return this.count - this.lowestCount;
    }
    clear() {
        this.count = this.lowestCount = 0;
        this.items = {};
    }
    toString() {
        if (this.isEmpty()) {
            return '';
        }
        let objString = `${this.items[this.lowestCount]}`;
        for (let i = this.lowestCount + 1; i < this.count; i++) {
            objString = `${objString},${this.items[i]}`;
        }
        return objString;
    }
}
let queue = new Queue();
console.log(queue.isEmpty());
queue.enqueue('Jack');
queue.enqueue('Jojn');
console.log(queue.toString());
queue.dequeue();
console.log(queue.toString());
console.log(queue.size());
//击鼓传花
function hotPotato(elementsList, num) {
    const queue = new Queue();
    console.log(queue.isEmpty());
    const elimitateList = [];
    for (let i = 0; i < elementsList.length; i++) {
        queue.enqueue(elementsList[i]);
    }
    while (queue.size() > 1) {
        // console.log(queue.size());
        for (let i = 0; i < num; i++) {
            queue.enqueue(queue.dequeue());
        }
        elimitateList.push(queue.dequeue());
    }
    return {
        elimitated: elimitateList,
        winner: queue.dequeue()
    }
}
const names = ['John', 'Jack', 'Camila', 'Ingrid', 'Carl'];
const result = hotPotato(names, 7);
result.elimitated.forEach(name => {
    console.log(`${name}在击鼓传花游戏中被淘汰`);
});
console.log(`胜利者：${result.winner}`);